package com.etc;


import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

/**
 * @Auther: zhezhe
 * @Date: 2018/10/2514:16
 * @Description:
 */
public class JobTest {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        System.setProperty("HADOOP_USER_NAME","root");
        Configuration configuration = new Configuration();

        configuration.set("mapred.job.tracker","master11:9000");


        Job job = Job.getInstance(configuration);

        //设置运行类,map类,reduce类
        job.setJarByClass(JobTest.class);
        job.setMapperClass(DataSortMap.class);
        job.setReducerClass(DataSortReduce.class);

        //设置输出key的类型
        job.setOutputKeyClass(IntWritable.class);
        //设置输出value的类型
        job.setOutputValueClass(IntWritable.class);

        //设置reduce的任务个数
        job.setNumReduceTasks(1);

        //mapreduce输入数据的文件/目录
        FileInputFormat.addInputPath(job,new Path("hdfs://master11:9000/inputsort/*"));
        //mapreduce执行后输出的数据目录
        FileOutputFormat.setOutputPath(job,new Path("hdfs://master11:9000/outputsort"));

        //执行完毕退出
        System.exit(job.waitForCompletion(true)?0:1);
    }
}
